package org.example.controller;

import org.example.App;
import org.example.pojo.UmsUser;
import org.example.service.IUmsUserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = App.class)
public class Service {
    @Resource
    JavaMailSenderImpl javaMailSender;
    @Resource
    IUmsUserService userService;
    @Resource
    BCryptPasswordEncoder bCryptPasswordEncoder;
    @Test
    public void setUser(){

    }

    @Test
    public void mail(){
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();

        try{
            MimeMessageHelper mimeMessageHelper = new MimeMessageHelper( mimeMessage,true );
            mimeMessageHelper.setFrom( "2106261058@qq.com","2106261058" );
            mimeMessageHelper.setTo( "weitongx01@gmail.com" );
            mimeMessageHelper.setSubject( "标题:产生式系统" );
            mimeMessageHelper.setText( "验证码：",true );
            javaMailSender.send( mimeMessage );
            System.out.println("发送完成");

        }catch (MessagingException e){
            e.printStackTrace();
        }catch (UnsupportedEncodingException e){
            e.printStackTrace();
        }

    }
}
